﻿using System;
using System.Collections.Generic;
using System.Text;
using TheCell;

namespace Unused
{
    class Unused_PossibilityUtils
    {
        public static void Possibility(List<Cell> cells)
        {
            foreach (Cell cell in cells)
            {
                if (cell.Status != CellStatus.Fixed)
                {
                    List<int> linevalue = Zonevalue(ClassifyUtils.Lines, cell.Location.X);
                    List<int> colvalue = Zonevalue(ClassifyUtils.Columns, cell.Location.Y);
                    List<int> areavalue = Zonevalue(ClassifyUtils.Areas, cell.Location.Area);
                    cell.Possible = Removeelement(cell.Possible, linevalue);
                    cell.Possible = Removeelement(cell.Possible, colvalue);
                    cell.Possible = Removeelement(cell.Possible, areavalue);
                    cell.Status = CellStatus.Calc;
                    if (cell.Possible.Count == 1)
                    {
                        cell.Status = CellStatus.Fixed;
                        cell.Value = cell.Possible[0];
                    }
                }
            }
        }
        private static List<int> Zonevalue(Dictionary<int, List<Cell>> pairs, int zone)
        {
            List<Cell> zonecells = null;
            List<int> zonevalue = null;
            pairs.TryGetValue(zone, out zonecells);
            foreach (Cell cell in zonecells)
            {
                if (!zonevalue.Contains(cell.Value))
                {
                    zonevalue.Add(cell.Value);
                }
            }
            return zonevalue;
        }
        private static List<int> Removeelement(List<int> first, List<int> removed)
        {
            foreach (int element in removed)
            {
                if (first.Contains(element))
                {
                    first.Remove(element);
                }
            }
            return first;
        }
    }
}
